package com.lanjiu.lib.imclient.dto.extra;

import android.text.TextUtils;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.pro.business.BusinessProtocolMessages;
import com.lanjiu.lib.imclient.dto.GroupMemberDto;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.dto.chat.ChatMessageDto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/18 16:24
 */
public class ChatGroupMsgDto extends Dto {

    private GroupMemberDto groupMemberDto;

    private String at;

    private ChatMessageDto chatMessageDto;

    public ChatGroupMsgDto() {
    }

    public ChatGroupMsgDto(GroupMemberDto groupMemberDto, ChatMessageDto chatMessageDto) {
        this.groupMemberDto = groupMemberDto;
        this.chatMessageDto = chatMessageDto;
    }

    public GroupMemberDto getGroupMemberDto() {
        return groupMemberDto;
    }

    public void setGroupMemberDto(GroupMemberDto groupMemberDto) {
        this.groupMemberDto = groupMemberDto;
    }

    public String getAt() {
        return at;
    }

    public void setAt(String at) {
        this.at = at;
    }

    public ChatMessageDto getChatMessageDto() {
        return chatMessageDto;
    }

    public void setChatMessageDto(ChatMessageDto chatMessageDto) {
        this.chatMessageDto = chatMessageDto;
    }

    @Override
    public BusinessProtocolMessages.GroupChatProtocol toProtobuf() {
        BusinessProtocolMessages.GroupChatProtocol.Builder groupChatProtocolBuilder = BusinessProtocolMessages.GroupChatProtocol.newBuilder();
        if (null != groupMemberDto) {
            if (IMSContacts.UserType.TOURISTS_USER.equals(groupMemberDto.getCurrentUserType())) {
                groupChatProtocolBuilder.setUserType(IMSContacts.UserType.TOURISTS_USER);
                groupChatProtocolBuilder.setTouristsGroupMember((BusinessProtocolEntities.TouristsGroupMember) groupMemberDto.toProtobuf());
            } else {
                groupChatProtocolBuilder.setUserType(IMSContacts.UserType.REGISTERED_USER);
                groupChatProtocolBuilder.setRegisteredGroupMember((BusinessProtocolEntities.RegisteredGroupMember) groupMemberDto.toProtobuf());
            }
        }
        if (null != chatMessageDto)
            groupChatProtocolBuilder.setChatMessage(chatMessageDto.toProtobuf());
        if(!TextUtils.isEmpty(at))
            groupChatProtocolBuilder.setAt(at);
        return groupChatProtocolBuilder.build();
    }
}
